
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>2、set - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>2、set - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Java集合框架中的`Set`接口主要用来解决什么问题？它的核心特性是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Set`接口用于存储不重复的元素。它的核心特性是集合中的元素必须是唯一的，不允许存储重复元素。</div>
          </div>
          <div class="card-source">来源: 1. Set 接口概述, 2. Set 接口的特点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`Set`接口在元素排序方面有什么特点？它是否允许存储`null`元素？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Set`接口不保证元素的顺序，其具体实现类可能按不同规则组织元素。大多数`Set`实现类允许存储一个`null`元素。</div>
          </div>
          <div class="card-source">来源: 2. Set 接口的特点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">请列举`Set`接口的三个常见实现类，并简述它们各自的底层数据结构和特点。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. `HashSet`：基于哈希表，是无序集合，提供O(1)的性能。<br>2. `LinkedHashSet`：内部使用链表维护元素的插入顺序。<br>3. `TreeSet`：基于红黑树，是有序集合，按元素的自然顺序或指定比较器排序。</div>
          </div>
          <div class="card-source">来源: 3. Set 接口的常见实现类</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">如果需要维持集合中元素的插入顺序，应该选择哪种`Set`实现类？它适合哪种应用场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该选择`LinkedHashSet`。它具有可预知的迭代顺序，适用于需要记住元素插入顺序的场景，比如LRU缓存的实现。</div>
          </div>
          <div class="card-source">来源: 5. 性能分析与适用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当把自定义对象存入`Set`集合时，为了确保其唯一性判断正确，必须对该对象做什么处理？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">需要重写该自定义对象的`equals()`和`hashCode()`方法，以确保`Set`能够正确判断对象的唯一性。</div>
          </div>
          <div class="card-source">来源: 6. Set 接口的注意事项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何使用`Set`接口提供的方法计算两个集合的交集、并集和差集？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以使用`retainAll()`方法求交集，`addAll()`方法求并集，以及`removeAll()`方法求差集。</div>
          </div>
          <div class="card-source">来源: 7. Set 接口的高级操作</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`HashSet`和`LinkedHashSet`是否是线程安全的？在多线程环境下使用时应注意什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`HashSet`和`LinkedHashSet`都不是线程安全的。如果在多线程环境下使用，需要进行外部同步。</div>
          </div>
          <div class="card-source">来源: 6. Set 接口的注意事项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">在什么场景下`TreeSet`是比`HashSet`更好的选择？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当需要按照元素的自然顺序或者指定的顺序来遍历集合时，`TreeSet`是更好的选择，因为它是一个有序集合。</div>
          </div>
          <div class="card-source">来源: 5. 性能分析与适用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何利用`Set`的特性来为一个`List`集合去重？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以利用`Set`不允许重复元素的特性，将含有重复元素的`List`作为构造函数参数来创建一个新的`Set`，从而实现去重。</div>
          </div>
          <div class="card-source">来源: 7. Set 接口的高级操作</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
